//
//  XFMessageTableViewController.m
//  sharedBooks
//
//  Created by XunFengKJ on 2016/11/18.
//  Copyright © 2016年 XunFengKJ. All rights reserved.
//

#import "XFMessageTableViewController.h"
#import "XFMessageTableViewCell.h"
#import "XFMessageModel.h"

static NSString * const reuseIdentifier = @"MessageCell";
@interface XFMessageTableViewController ()

@end

@implementation XFMessageTableViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"消息";
}

-(void)initViews{
    [self initTableView];
    [self headerRereshing];
}

- (void)initTableView{
    [self initTableViewWithStyle:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:[NSString stringWithFormat:@"%@",[XFMessageTableViewCell class]] bundle:nil ] forCellReuseIdentifier:reuseIdentifier];
    self.tableView.backgroundColor = XFUIColorFromRGB(0xf0f2f5);
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    //设置cell的估计高度
    self.tableView.estimatedRowHeight = 30;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}

#pragma mark - Data Source
- (void)loadDefaultDataSource{
    [super loadDefaultDataSource];
    self.blankHintImage = [UIImage imageNamed:@""];
    self.blankHintString=@"暂无消息";
}

-(void)loadDataSource{
    
    WEAKSELF
    if (self.requestCurrentPage!=1) {
        [self.HUD showAnimated:YES];
    }
//    [XFPostRequest postBookMessageWithUid :[BookShareUserInforDefault readUserUid] page:[NSString stringWithFormat:@"%zd",self.requestCurrentPage] success:^(id responseObject) {
//        LGFLog(@"===%@",responseObject);
//        [weakSelf hideLoading];
//        if (responseObject == nil)  return ;
//        if ([responseObject[@"status"] intValue] == 1003)
//        {
//            NSString *pageStr =  [[responseObject[@"msg"] componentsSeparatedByString:@"|"] lastObject];
//            NSInteger page =  [pageStr integerValue];
//
//            [weakSelf addToDataSource:[XFMessageModel mj_objectArrayWithKeyValuesArray:responseObject[@"content"]]];
//            if (weakSelf.requestCurrentPage == page) {
//                //                XFMessageModel *model = [XFMessageModel new];
//
//                weakSelf.isPageEnd=YES;
//            }else{
//                weakSelf.isPageEnd=NO;
//            }
//        }
//        else {
//            if (![[XFMessageModel mj_objectArrayWithKeyValuesArray:responseObject[@"content"]] isKindOfClass:[NSArray class]]) {
//                [weakSelf.dataSource removeAllObjects];
//                [weakSelf reloadDataWithBlank];
//            }
//
//            [weakSelf endPullDownRefreshing];
//            [weakSelf setIsPageEnd:YES];
//        }
//        [weakSelf.tableView reloadData];
//    } failure:^(NSError *error) {
//        [weakSelf hideLoading];
//        [MBProgressHUD showError:LNETWORKERROR];
//    }];
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    LGFLog(@"self.dataSource.count = %zd",self.dataSource.count);
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    XFMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    XFMessageModel * messageModel = self.dataSource[indexPath.row];
    cell.model = messageModel;
    return cell;
}

@end
